	.text
	.section .rodata
	.align	3
add_str:
	.string	"%d+%d=%d\n"
	.align	3
sub_str:
	.string	"%d-%d=%d\n"

# if test function
	.text
	.align	1
	.globl	if_test
	.type	if_test, @function
if_test:
	addi	sp, sp, -32	# allocate stack
	sd	ra, 0(sp)	# store ra

	bnez	a0, sub_case
	addw	a3, a1, a2
	lla	a0, add_str
	call	printf@plt
	beq	x0, x0, exit_if

sub_case:
	subw	a3, a1, a2
	lla	a0, sub_str
	call	printf@plt

exit_if:
	ld	ra, 0(sp)	# restore ra
	addi	sp, sp, 32	# free stack
	jr	ra
	.size	if_test, .-if_test

# man function
	.section	.rodata
	.align	3
message:
	.string	"Needed 3 parameters"
	.section .text
	.align	1
	.globl	main
	.type	main, @function
main:
	addi	sp,sp,-32
	sd	ra,24(sp)
	sd	s0,16(sp)
	sd	s1,8(sp)
	li	a5,4
	bne	a0,a5, param_error

	ld	a0,8(a1)
	mv	s0,a1
	li	a2,10
	li	a1,0
	call	strtol@plt

	mv	s1,a0
	ld	a0,16(s0)
	li	a2,10
	li	a1,0
	call	strtol@plt

	mv	a5,a0
	ld	a0,24(s0)
	li	a2,10
	li	a1,0
	mv	s0,a5
	call	strtol@plt

	sext.w	a2,a0
	sext.w	a1,s0
	sext.w	a0,s1
	call	if_test

	li	a0,0
	j	exit

param_error:
	lla	a0, message
	call	puts@plt
	li	a0,-1

exit:
	ld	ra,24(sp)
	ld	s0,16(sp)
	ld	s1,8(sp)
	addi	sp,sp,32
	jr	ra
	.size	main, .-main
